package org.unit.testmgmt.ui.actions;

import java.util.logging.Logger;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IActionDelegate;
import org.unit.testmgmt.messages.Messages;

/**
 * The action for the test class generation.
 * 
 * @author Robert Streng
 *
 */
public class GenerateUnitTestclassAction extends UTMAction {
	
	private Logger logger = Logger.getLogger(this.getClass().getName());
	private String information = Messages.General_information;
	private String error = Messages.General_error;
	private String errorMsg = Messages.General_error_processing;
	
	/**
	 * Constructor
	 */
	public GenerateUnitTestclassAction() {
		super();
	}

	/**
	 * @see IActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		super.run(action);
		
		try {
			boolean result = getUTMController().generateTestclass(workbenchWindow, selection);
			if (result)
				MessageDialog.openInformation(shell, information,
						Messages.General_info_generation_successful);
			
		} catch (Exception e) {
			logger.severe(ExceptionUtils.getFullStackTrace(e));
			MessageDialog.openError(shell, error, errorMsg);
		}
		
	}

}
